/*LICENSE_BEGIN
 * ******************************************************************
 * All original parts of SoccerScope2003 have copyright (2003) by
 * Team YowAI, represented by Mr. Shuhei Shiota
 * The Department of Creative Informatics
 * The Graduate School of Information Science and Technology
 * The University of Tokyo
 * 
 * Additional classes (except libraries in /lib) were developed by 
 * the Dainamite Robocup-Team of the DAI-Labor, TU-Berlin 
 * (www.dai-labor.de)
 * 
 * Extended/new classes/packages are:
 *   soccerscope.analyzer.LogfileAnalyzer
 *   soccerscope.daistatistic.*
 *   soccerscope.daistatistic.charts.*
 *   soccerscope.daistatistic.tools.*
 *   soccerscope.db.*
 *   soccerscope.dialog.*
 *   soccerscope.model.PlayerWorldModel
 *   soccerscope.model.SimplePlayer
 *   soccerscope.net.AgentConnector
 *   soccerscope.training.*
 *   soccerscope.training.conditions.*
 * ******************************************************************
LICENSE_END*/
package soccerscope.training.conditions;

import soccerscope.model.ClientScene;
import soccerscope.model.PlayMode;
import soccerscope.model.WorldModel;
import soccerscope.model.PlayMode.PLAY_MODE;

public class PlayModeCondition extends GameCondition {

	PLAY_MODE[] playModes = null;

	private PLAY_MODE fulfilling = null;

	public PlayModeCondition() {
		super();
	}

	public void setPlayModes(PLAY_MODE[] playModes) {
		this.playModes = playModes;
	}

	public PLAY_MODE[] getPlayModes() {
		return this.playModes;
	}

	/**
	 * This method overrides the isTrue() method from gamecondition to specifiy
	 * the behaviour of the Play_Mode Condition
	 */
	@Override
	public boolean isTrue(ClientScene scene) {
		if (this.playModes == null)
			return false;
		for (PLAY_MODE p : this.playModes) {
			if (p == PlayMode.allPlayModes[scene.pmode.pmode]) {
				setFulfillingPMode(p);
				System.out
						.println(""
								+ WorldModel.getInstance().getSceneSet()
										.lastScene().time
								+ " PlayMode-Condition fulfilled: " + p);
				return true;
			}
		}
		return false;
	}

	public int getFulfillingIndex() {
		return this.fulfilling.ordinal() + 3;
	}

	private void setFulfillingPMode(PLAY_MODE pm) {
		this.fulfilling = pm;
	}

	public int[] getStatIndizes() {
		int s = this.playModes.length;
		int[] indizes = new int[s];
		for (int i = 0; i < s; i++) {
			indizes[i] = this.playModes[i].ordinal() + 3;
		}
		return indizes;
	}
}
